<template>
  <div class="goods-item" @click="goodsClick">
    <img v-lazy="showImage" class="img" @load="imgLoad"/>
    <div class="title">{{goodsItem.title}}</div>
    <div class="goods-info">
      <span class="price">￥{{parseInt(goodsItem.price).toFixed(2)}}</span>
      &nbsp;
      <div class="collect-box">
        <img src="../../../assets/img/common/collect.svg" class="icon">
        <span class="collect">{{(goodsItem.cfav)}}</span>
      </div>

    </div>

  </div>
</template>

<script>
  export default {
    name: 'GoodsListItem',
    props: {
      goodsItem: {
        type: Object,
        default() {
          return {};
        }
      }
    },
    computed: {
      showImage() {
        return this.goodsItem.image || this.goodsItem.show.img;
      }
    },
    methods: {
      imgLoad() {
        // console.log(222, this.$route.path);
        if (this.$route.path === '/home') {

          this.$bus.$emit('itemImgLoad');
        } else if (this.$route.path === '/detail') {
          this.$bus.$emit('detailItemImgLoad');
        }

      },

      goodsClick() {

        if (this.goodsItem.iid) {
          this.$router.push('/detail/' + this.goodsItem.iid);
        } else {
          console.log(999, this.goodsItem);
          this.$router.push('/detail/' + this.goodsItem.item_id);
        }

      }

    }
  };
</script>

<style scoped>

  .goods-item {
    width: 48%;
    padding-bottom: 20px;
  }

  .title {
    /*font-size: 12px;*/
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical
  }

  .img {
    height: 280px;
    width: 100%;
    border-radius: 5px;
  }

  .goods-info{
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }

  .collect-box {
    display: flex;
  }

  .icon{
    width: 20px;
    height: 20px;
  }


  .price {
    color: var(--color-tint);
  }

  .collect {
    margin-left: 4px;
    margin-right: 6px;
  }

</style>
